package com.qianfeng.shoon.pet.ui;

import android.support.v4.app.Fragment;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.qianfeng.shoon.pet.BaseApp;
import com.qianfeng.shoon.pet.R;
import com.qianfeng.shoon.pet.fragment.AboutFragment;
import com.qianfeng.shoon.pet.fragment.HomeFragment;
import com.qianfeng.shoon.pet.fragment.MudidiFragment;
import com.qianfeng.shoon.pet.fragment.TimeFragment;
import com.qianfeng.shoon.pet.fragment.WorldFragment_;
import com.qianfeng.shoon.pet.utils.AppManager;
import com.qianfeng.shoon.pet.utils.FragmentTabUtils;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

import java.util.ArrayList;

@EActivity(R.layout.activity_main)
public class MainActivity extends BaseActivity implements FragmentTabUtils.OnRgsExtraCheckedChangedListener, RadioGroup.OnCheckedChangeListener,RadioButton.OnCheckedChangeListener{

    @ViewById
    CheckBox footerHomeRbtn;
    private ArrayList<Fragment> fragments = new ArrayList<Fragment>();
    @ViewById
    FrameLayout mainFragmentContainer;
    @ViewById
    RadioButton footerWordRbtn;
    @ViewById
    RadioButton footerTimeRbtn;
    @ViewById
    RadioButton footerMyRbtn;
    @ViewById
    RadioButton footerAboutRbtn;
    @ViewById
    RadioGroup mainRgs;

    private long time;

    @AfterViews
    void initView() {
        fragments.add(new WorldFragment_());
        fragments.add(new TimeFragment());
        fragments.add(new HomeFragment());
        fragments.add(new MudidiFragment());
        fragments.add(new AboutFragment());
        new FragmentTabUtils(getSupportFragmentManager(),fragments,R.id.main_fragment_container,mainRgs,footerHomeRbtn,this);
    }





    @Override
    public void onBackPressed() {
        long currentTime = System.currentTimeMillis();
        if (currentTime - time > 1000) {
            time = currentTime;
            BaseApp.getInstance().showToast("再按一次退出程序");
        } else {
            AppManager.getAppManager().AppExit(BaseApp.getInstance());
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        BaseApp.getInstance().unegisterNetworkStateReceiver();
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        BaseApp.getInstance().unegisterNetworkStateReceiver();
    }

    @Override
    public void OnRgsExtraCheckedChanged(RadioGroup radioGroup, int checkedId, int index) {

    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        BaseApp.getInstance().unegisterNetworkStateReceiver();
    }



}
